﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NeuralNetworks
{
    public class NeuronsLayer
    {
        #region Constructors

        public NeuronsLayer(int neuronsCount, NeuronsLayer nextLayer)
        {
            _neurons = new Neuron[neuronsCount];
            _nextLayer = nextLayer;

            this.CreateNeurons();
        }

        #endregion

        #region Private Members

        private NeuronsLayer _nextLayer;

        #endregion

        #region Attributes and Properties

        private Neuron[] _neurons;
        public Neuron[] Neurons
        {
            get { return _neurons; }
        }

        #endregion

        #region Private Methods

        private void CreateNeurons()
        {
            for (int i = 0; i < _neurons.Count(); i++)
            {
                if (_nextLayer != null)
                    _neurons[i] = new Neuron(_nextLayer.Neurons);
                else
                    _neurons[i] = new Neuron();
            }
        }

        #endregion

        #region Public Methods

        public void Propagate()
        {
            for (int i = 0; i < _neurons.Count(); i++)
                _neurons[i].CalculateAndPropagateValue();
        }

        public void CalculateErrors()
        {
            for (int i = 0; i < _neurons.Count(); i++)
                _neurons[i].CalculateError();
        }

        public void UpdateWeights()
        {
            for (int i = 0; i < _neurons.Count(); i++)
                _neurons[i].UpdateWeights();
        }

        #endregion
    }
}
